package com.ylkj.bus.dispatcher;

import com.ylkj.Application;
import com.ylkj.bus.MessageContent;
import com.ylkj.bus.dispatcher.handler.DeviceOnlineDataStreamHandler;
import org.apache.flink.streaming.api.datastream.DataStream;

import java.util.Properties;

/**
 * @Author: wengzx
 * @Date: 2025/4/18
 * @Desc:
 */
public enum DispatcherHandler {
    //处理数据供用采使用
    IOT_DEVICE_ONLINE_DATA {
        @Override
        protected IStreamHandler getHandler(Properties flinkProperties) {
            String tableName = flinkProperties.getProperty("sink.rds.tableName");
            return new DeviceOnlineDataStreamHandler(
                    Application.getRdsConfig(flinkProperties),
                    tableName,
                    Application.getDataHubSinkConfig(flinkProperties)
            );
        }
    };

    protected abstract IStreamHandler getHandler(Properties flinkProperties);

    public void dispatch(DataStream<MessageContent> stream, Properties flinkProperties) {
        getHandler(flinkProperties).handle(stream);
    }
}
